package com.jzbwlkj.windowmanager;

/**
 * Created by chenx on 2017/11/7.
 */

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class MyArrayAdapter extends ArrayAdapter<String>
{
    private Context mContext;
    private String[] mStringArray;

    public MyArrayAdapter(Context context, String[] stringArray)
    {
// 注意：此处使用了系统默认item样式，所以getDropDownView和getView函数中TextView控件必须使用系统默认的text1名称
        super(context, android.R.layout.simple_spinner_item, stringArray);
        mContext = context;
        mStringArray = stringArray;
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent)
    {
// 修改Spinner下拉字体颜色
        if (convertView == null)
        {
            LayoutInflater inflater = LayoutInflater.from(mContext);
            convertView = inflater.inflate(android.R.layout.simple_spinner_dropdown_item, parent,
                    false);
        }

// 注意：text1是系统默认Spinner用来显示文字的TextView控件名称，不可以修改
        TextView txtvwDropdown = (TextView) convertView.findViewById(android.R.id.text1);
        txtvwDropdown.setText(mStringArray[position]);
        txtvwDropdown.setTextColor(Color.BLACK);
        txtvwDropdown.setBackgroundColor(Color.WHITE);

        return convertView;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
// 修改Spinner显示字体颜色
        if (convertView == null)
        {
            LayoutInflater inflater = LayoutInflater.from(mContext);
            convertView = inflater.inflate(android.R.layout.simple_spinner_item, parent, false);
        }


//注意：text1是系统默认Spinner用来显示文字的TextView控件名称，不可以修改
        TextView txtvwDisplay = (TextView) convertView.findViewById(android.R.id.text1);
        txtvwDisplay.setText(mStringArray[position]);
        txtvwDisplay.setTextColor(Color.BLACK);
        return convertView;
    }
}